package com.ld.security.auth.sdk.util;


import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.codec.Hex;
import org.springframework.security.crypto.keygen.BytesKeyGenerator;
import org.springframework.security.crypto.keygen.KeyGenerators;

/**
 * @Description:
 * @ClassName:PasswordUtil
 * @Author:Player
 * @Date:2019-05-31 10:50
 **/
public class PasswordUtil {

    /*加密密码*/
    public static String encoderPassword(String password) {
        return new BCryptPasswordEncoder().encode(password);
    }

    /*密码校验*/
    public static Boolean matchesPassword(String rawPassword, String encodedPassword) {
        return new BCryptPasswordEncoder().matches(rawPassword, encodedPassword);
    }

    /*生成salt*/
    public static String generatorSalt() {
        return String.valueOf(Hex.encode(KeyGenerators.secureRandom(32).generateKey()));
    }
}
